//
//  CommonToolClass.m
//  VideoTeleprompter
//
//  Created by Duncan on 2021/4/19.
//

#import "CommonToolClass.h"

@interface CommonToolClass ()

@property (nonatomic, weak) id aTarget;
@property (nonatomic, assign) SEL aSelector;

@end

@implementation CommonToolClass

+ (NSString *)secondsForDay:(NSInteger)count {
    NSString *str;
    str = [NSString stringWithFormat:@"%02ld:%02ld:%02ld", count/3600, count%3600/60, count%3600%60];
    return str;
}
+ (NSString *)timeVwStrWithSecTime:(NSInteger)secTime {
    NSInteger time = secTime;
    
    if (time / 3600 > 0) { // 时分秒
        NSInteger hour   = time / 3600;
        NSInteger minute = (time % 3600) / 60;
        NSInteger second = (time % 3600) % 60;
        
        return [NSString stringWithFormat:@"%02zd:%02zd:%02zd", hour, minute, second];
    } else { // 分秒
        NSInteger minute = time / 60;
        NSInteger second = time % 60;
        
        return [NSString stringWithFormat:@"%02zd:%02zd", minute, second];
    }
}

#pragma mark ------- 定时器 -------

+ (instancetype)ps_scheduledTimerWithTimeInterval:(NSTimeInterval)ti target:(id)aTarget selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)yesOrNo {
    
    CommonToolClass *weakTimer = [[self alloc] init];
    weakTimer.aTarget = aTarget;
    weakTimer.aSelector = aSelector;
    
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:ti target:weakTimer selector:@selector(ps_fire:) userInfo:userInfo repeats:yesOrNo];
    weakTimer.timer = timer;
    
    return weakTimer;
}

- (void)ps_timerInvalidate {
    [self.timer invalidate];
    self.timer = nil;
}

- (void)ps_fire:(id)userInfo {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Warc-performSelector-leaks"
    [self.aTarget performSelector:self.aSelector withObject:userInfo];
#pragma clang diagnostic pop
}

#pragma mark ------- 逻辑判断方法 -------

+ (BOOL)judgePhoenString:(NSString *)phone {
    NSString *info = @"";
    if (phone.length == 0) {
        info = @"手机号不能为空";
    } else {
        
    }
    
    if (info.length == 0) {
        return YES;
    } else {
        [OCProgress_HUD showInfoWithStatus:info];
        return NO;
    }
}

+ (BOOL)judgePasswordString:(NSString *)password {
    NSString *info = @"";
    if (password.length == 0) {
        info = @"密码不能为空";
    } else {
        
    }
    
    if (info.length == 0) {
        return YES;
    } else {
        [OCProgress_HUD showInfoWithStatus:info];
        return NO;
    }
}

/// 判断验证码
+ (BOOL)judgeCodeString:(NSString *)code {
    NSString *info = @"";
    if (code.length == 0) {
        info = @"验证码不能为空";
    } else {
        
    }
    
    if (info.length == 0) {
        return YES;
    } else {
        [OCProgress_HUD showInfoWithStatus:info];
        return NO;
    }
}

/// 判断是否绑定手机号，没有则提示
+ (BOOL)isBindMobilePhoneAndShowTips:(NSString *)tips {
//    if (kIsEmpty([QXUserMainService share].userModel.mobile)) {
//        QXTitleBaseShowView *titleShow = [[QXTitleBaseShowView alloc] init];
//        [titleShow setMessageString:tips];
//        [titleShow.doneButton setTitle:@"去绑定" forState:0];
//        titleShow.isTouchBackHid = YES;
//
//        titleShow.doneBlock = ^{
//            QXBindPhoneViewController *vc = [[QXBindPhoneViewController alloc] init];
//            [[UIApplication currentViewController].navigationController pushViewController:vc animated:YES];
//        };
//        [titleShow show];
//        return NO;
//    }
    return YES;
}

@end
